package servlet.huwenyao;

import net.sf.json.JSONObject;
import service.OrderService;
import service.impl.OrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(value = "/DeleteOrderServlet")
public class DeleteOrderServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置返回的格式
        response.setContentType("text/json;charset=utf-8");
        //获取ID参数
        OrderService os = new OrderServiceImpl();
        int bo=os.deleOrder(Integer.parseInt(request.getParameter("id")));
        JSONObject json=new JSONObject();
        if(bo>0){
            json.put("msg","删除成功");
        }else{
            json.put("msg","删除失败");
        }
        PrintWriter out = response.getWriter();
        out.print(json);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
